/*************************************************************************
 * Tic Tac Toe
 *
 * Author: Justin Sheppard
 * Student #: 200811917
 * E-Mail: justin.sheppard@mun.ca
 * ***********************************************************************/

package tictactoe;

import java.util.Random;

/** DumbAI *****************************************************************
 * 
 * A class that implements the AI interface. The DumbAI does not care about
 * winning, and just enjoys playing the game.
 * 
 * ****************************************************************************/
public class DumbAI implements AI {
	
	private char aiPiece;
	
	/** Constructor *****************************************************************
	 * 
	 * Simply creates an object with a piece opposite of the player's.
	 * 
	 * @pre		-	
	 * @params	- aiIsX: True if the player wants to play as O
	 * @returns - 
	 * @post	- 
	 * ****************************************************************************/
	public DumbAI(boolean aiIsX){
		if(aiIsX)
			aiPiece = 'X';
		else
			aiPiece = 'O';
	}
	
	/** chooseMove *****************************************************************
	 * 
	 * Randomly places a piece in an open position.
	 * @pre		-	
	 * @params	- board: Used to check the current board's open positions
	 * @returns - The AI's Move with the corresponding row, col index and its piece.
	 * @post	-
	 * ****************************************************************************/
	@Override
	public Move chooseMove(Board board) {
		
		Move aiMove;
		Random gen = new Random();	//Random # generator
		int i = gen.nextInt(3);	//nextInt gets random int from 0-n EXCLUSIVE (so 3 => 0-2)
		int j = gen.nextInt(3);
		
		boolean empty = false;	//Is the position empty
		
		while(!empty)
			if(board.get(i, j) != ' '){
				i = gen.nextInt(3);
				j = gen.nextInt(3);
			}else{
				empty = true;
			}
		
		aiMove = new Move(i, j, aiPiece);
		return aiMove;
	}

}
